﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Saker.Kernel.BLL
{
    public class RevokeMemory
    {
        [DllImport("kernel32.dll")]
        public static extern bool GetProcessWorkingSetSize(IntPtr proc, out int min, out int max);
        public static string ReduceMemoryFootPrint()
        {
            int min = 0;
            int max = 0;
            Process currentProcess = Process.GetCurrentProcess();
            try
            {
                if (GetProcessWorkingSetSize(currentProcess.Handle, out min, out max))
                {
                    currentProcess.MinWorkingSet = (IntPtr)min;
                }
                return "";
            }
            catch (Exception exception)
            {
                return ((("MinWorkingSet value is set to: " + min.ToString()) + " Process In Error: " + currentProcess.ProcessName) + exception.StackTrace);
            }
        }

        [DllImport("kernel32.dll")]
        public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
    }
}
